package com.plate.auth.expection;

import com.plate.auth.utils.ResponseUtils;
import com.plate.common.core.result.Result;
import com.plate.common.core.result.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName OAuthServerAuthenticationEntryPoint
 * @Description TODO
 * @Author jiaxd
 * @Date 2023年10月29日 18:15
 * @Version 1.0
 */

@Slf4j
@Component
public class OAuthServerAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        log.error(ResultCode.CLIENT_AUTHENTICATION_FAILED.name());
        ResponseUtils.result(response, Result.FAIL(ResultCode.CLIENT_AUTHENTICATION_FAILED));
    }
}
